package com.tianquan.mapper;


import com.tianquan.DistributedLock.entiy.Lock;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

/**
 * @author 天权
 * @description 针对表【lock】的数据库操作Mapper
 * @createDate 2024-09-25 08:59:28
 * @Entity generator.domain.Lock
 */

@Mapper
public interface LockMapper {

    /**
     * 获取锁
     *
     * @return 是否获取到锁
     */
    int lock(Lock lock);

    /**
     * 释放锁
     *
     * @param lockName 锁的key
     * @param threadId 线程id
     * @return 是否释放成功
     */
    int unlock(String lockName, long threadId);

    /**
     * 判断锁是否存在
     *
     * @param lockName 锁的key
     * @return 锁信息
     */
    Lock isExist(String lockName);


    /**
     * @description: 可重入锁
     * @author: tianquan
     * @date: 2024/9/26 下午5:32
     * @param: [lockName, flag]
     * @return: int
     **/
    int lockReentrant(String lockName, Boolean flag);

    /**
     * @description: 删除锁
     * @author: tianquan
     * @date: 2024/9/26 下午5:32
     * @param: [lockName]
     * @return: void
     **/
    void delete(@Param("lockName") String lockName);


    /**
     * @description: 续约
     * @author: tianquan
     * @date: 2024/9/26 下午5:34
     * @param: [lock]
     * @return: void
     **/
    void renewal(Lock lock);
}
